
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加端口扫描任务</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">

    <div class="layui-form-item">
        <label class="layui-form-label required">任务名</label>
        <div class="layui-input-block">
            <input type="text" name="CusName" lay-verify="required" lay-reqtext="任务名不能为空" placeholder="请输入任务名"
                   class="layui-input">
            <tip>若追加已有任务,请填写该任务名。如果有多个扫描任务同时运行，则不保证消息队列顺序(消息发送是随机的)</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">主机地址</label>
        <div class="layui-input-block">
            <textarea name="Hosts" class="layui-textarea" lay-verify="required" placeholder="192.168.1.1/24"></textarea>
            <tip>可添加多行,支持CIDR格式,自动去重处理</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">端口</label>
        <div class="layui-input-block">
            <input type="text" name="Ports" lay-verify="required" value="top1000" valay-reqtext="端口参数不能为空" placeholder="请输入端口参数"
                   class="layui-input">
            <tip>格式：80(单端口)、21,22,23(指定多个端口)、1-100(端口范围)、top100(内置top100端口)、top1000(内置top1000端口)、full(全部端口)</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">扫描速率</label>
        <div class="layui-input-block">
            <input type="text" name="Rate" lay-verify="required|number" value="1000" valay-reqtext="扫描速率不能为空" placeholder="请输入扫描速率"
                   class="layui-input">
            <tip>扫描速率过大会导致扫描结果不全,外网扫描建议不超过2000</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">探测超时</label>
        <div class="layui-input-block">
            <input type="text" name="Timeout" lay-verify="required|number" value="1000" valay-reqtext="扫描超时不能为空" placeholder="请输入扫描超时"
                   class="layui-input">
            <tip>默认为10s</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">存活探测</label>
        <div class="layui-input-block">
            <input type="checkbox" name="Ping" lay-skin="switch" lay-filter="switchPing" lay-text="ON|OFF">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">优先探测</label>
        <div class="layui-input-block">
            <select name="Detection" lay-filter="youxian">
                <option value="null">无</option>
                <option value="top100">top-100</option>
                <option value="top1000">top-1000</option>
            </select>
            <tip>对于禁ping扫描，会扫描所有主机(不管是否存活),会浪费大量时间，可使用优先探测top100或top1000端口进行存活扫描</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">指纹超时</label>
        <div class="layui-input-block">
            <input type="text" name="NmapTimeout" lay-verify="required|number" value="7" valay-reqtext="指纹识别超时不能为空" placeholder="请输入指纹识别超时"
                   class="layui-input">
            <tip>指纹识别超时默认为7s</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">WAF过滤</label>
        <div class="layui-input-block">
            <input type="text" name="WafNum" lay-verify="required|number" value="50" valay-reqtext="waf过滤不能为空" placeholder="请输入waf过滤"
                   class="layui-input">
            <tip>默认单个主机超过50个端口开放则判定为waf，不继续探测</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">重试次数</label>
        <div class="layui-input-block">
            <input type="text" name="Retries" lay-verify="required|number" value="1" valay-reqtext="重试次数不能为空" placeholder="请输入重试次数"
                   class="layui-input">
            <tip>若超时则重新探测</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">二次验证</label>
        <div class="layui-input-block">
            <input type="checkbox" name="Verify" lay-skin="switch" lay-filter="switchVerify" lay-text="ON|OFF">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="PortScanAdd">添加任务</button>
        </div>
    </div>
</div>
<blockquote class="layui-elem-quote layui-text">
    端口扫描使用消息队列进行分布式扫描，使用自研nmaps端口扫描器，详情请点击 <a href="https://github.com/CTF-MissFeng/nmaps" target="_blank">nmaps</a>
</blockquote>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function() {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听存活探测开关
        form.on('switch(switchPing)', function(data){
            if(this.checked){
                layer.tips('温馨提示：开启存活探测会漏掉防火墙禁ping的主机,但会加快扫描速度', data.othis)
            }
        });

        //监听二次验证开关
        form.on('switch(switchVerify)', function(data){
            if(this.checked){
                layer.tips('温馨提示：二次验证使用connect连接验证扫描出的端口，但会浪费一点时间,提高准确度', data.othis)
            }
        });

        //监听提交
        form.on('submit(PortScanAdd)', function(data) {
            var loading = layer.load();
            var jsonObj = data.field;
            jsonObj.WafNum = parseInt(jsonObj.WafNum);
            jsonObj.Retries = parseInt(jsonObj.Retries);
            jsonObj.Rate = parseInt(jsonObj.Rate);
            jsonObj.Timeout = parseInt(jsonObj.Timeout);
            jsonObj.NmapTimeout = parseInt(jsonObj.NmapTimeout);
            if(jsonObj.Verify=="on"){
                jsonObj.Verify = true;
            }else{
                jsonObj.Verify = false;
            }
            if(jsonObj.Ping=="on"){
                jsonObj.Ping = true;
            }else{
                jsonObj.Ping = false;
            }
            if (jsonObj.Ping&&(jsonObj.Detection!="null")){
                layer.close(loading);
                layer.alert("存活探测和优先探测不能同时开启", {
                    title: '提示',
                    icon: 2
                })
                return false;
            }
            $.ajax({
                url: "/api/util/portscan/add",
                data: JSON.stringify(jsonObj),
                contentType: 'application/json;charset=UTF-8',
                dataType: 'json',
                async:true,
                type: 'post',
                success: function(result) {
                    layer.close(loading);
                    if (result.code == 200) {
                        var index = layer.alert(result.msg, {
                            title: '提示',
                            icon: 1
                        }, function() {
                            parent.layui.table.reload("currentTable_portscanmanager");
                            layer.close(index);
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        })
                    } else {
                        layer.alert(result.msg, {
                            title: '提示',
                            icon: 2
                        })
                    }
                },
                error: function (e) {
                    layer.close(loading);
                    layer.alert(JSON.stringify(e), {title: '提示', icon: 2})
                }
            })
            return false;
        });
    });
</script>
</body>
</html>
